home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / ODUtils / PlfmFile.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-17  |  9.0 KB  |  298 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        PlfmFile.h
  3.  
  4.     Contains:    Platform-file wrapper class
  5.  
  6.     Owned by:    Vincent Lo
  7.  
  8.     Copyright:    © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <5>     6/27/96    jpa        T10012: Changed kODMagicFileTypeChar to
  13.                                     avoid conflict w/developer
  14.          <4>     5/31/96    jpa        T10012: Added IsOpenDocDocument.
  15.          <3>     5/24/96    jpa        1.1MRD: pragma internal.
  16.          <2>      5/8/96    NP        1282265: saving as stationery looks like
  17.                                     document
  18.  
  19.     To Do:
  20.     In Progress:
  21.         
  22. */
  23.  
  24. #ifndef _PLFMFILE_
  25. #define _PLFMFILE_
  26.  
  27. #ifndef _ODTYPES_
  28. #include "ODTypes.h"
  29. #endif
  30.  
  31. #ifndef _PLFMDEF_
  32. #include "PlfmDef.h"
  33. #endif
  34.  
  35. #ifndef _ODMEMORY_
  36. #include "ODMemory.h"
  37. #endif
  38.  
  39. #ifndef _ITEXT_
  40. #include "IText.h"        /* For ODScriptCode type */
  41. #endif
  42.  
  43. #ifndef __FILES__
  44. #include <Files.h>
  45. #endif
  46.  
  47. //==============================================================================
  48. // Theory of Operation
  49. //==============================================================================
  50.  
  51. //==============================================================================
  52. // Constants
  53. //==============================================================================
  54.  
  55. const unsigned char kODMagicFileTypeChar    = 0xCD;
  56.                     // Magic 1st char of filetype ('Õ' or option-n, shift-o)
  57.  
  58. const    ODSShort    kODNoFileRefNum         = 0;
  59. const    ODSShort    kODMaxFileNameSize        = 31;
  60. const    ODULong        kODNoFileID                = 0;
  61.  
  62. //==============================================================================
  63. // Scalar Types
  64. //==============================================================================
  65.  
  66. typedef FSSpec        ODFileSpec;
  67. typedef short        ODFileRefNum;
  68. typedef ODSByte        ODFilePermission;
  69.  
  70. typedef ODFileRefNum    *ODFileRefNumPtr;
  71.  
  72. enum PFUniquifyAction { kSpecifyNewNameOnly, kRenameInPlace };
  73.  
  74. const    ODBoolean    kODTryCurrentName    = kODFalse;
  75. const    ODBoolean    kODForceNewName     = kODTrue;
  76.  
  77. const    ODSShort    kODNoResourceID = 0;
  78.  
  79. //==============================================================================
  80. // Classes defined in this interface
  81. //==============================================================================
  82.  
  83. class PlatformFile;
  84. class CWithActiveResources;        // private class
  85.  
  86.  
  87. //==============================================================================
  88. // PlatformFile
  89. //==============================================================================
  90.  
  91. #ifdef PRAGMA_INTERNAL_SUPPORTED
  92. #pragma internal on
  93. #endif
  94.  
  95. class PlatformFile
  96. {    
  97. public:
  98.  
  99.     PlatformFile();
  100.    ~PlatformFile();
  101.  
  102. // Methods you can call when the file is not open:
  103.     // pointing the PlatformFile at a physical file    and setting default opening permissions
  104.     // Specify() can only be called once on the object. If it is being called more than once,
  105.     // the behavior is unpredictable. If you want to work with a different file,
  106.     // you need to delete the current object and create a new one. 
  107.     ODNVMethod    void        Specify(const ODFileSpec* fileSpec);
  108.     ODNVMethod    void        SpecifyFromFile(PlatformFile* file);
  109.     ODNVMethod    void        SetAsciiName(const char* name);
  110.     inline        void        SetPermission(ODFilePermission filePermission);
  111.     // create/open/delete the file
  112.     inline        void        SetFileRefNum( ODFileRefNum );
  113.     ODNVMethod    void        Create(ODOSType creator, ODOSType fileType, ODScriptCode scriptCode);
  114.     ODNVMethod    void        Open();
  115.     ODNVMethod    void        Delete();
  116.  
  117.     // These are optional and simply optimize multiple resource calls
  118.     ODNVMethod    void        OpenResFile();
  119.     ODNVMethod    void        CloseResFile();
  120.     // create the resource fork (only to be used after Create).
  121.     ODNVMethod    void        CreateResFile();
  122.  
  123. // Methods you can call anytime after calling Specify or SetAsciiName
  124.     ODNVMethod    ODBoolean    IsEqualTo(PlatformFile* file);
  125.     ODNVMethod    ODBoolean    IsLocked();
  126.     ODNVMethod    void        Lock();
  127.     ODNVMethod    void        Unlock();
  128.     ODNVMethod    ODBoolean    IsStationery();
  129.     ODNVMethod    void        SetStationery(ODBoolean isStationery);
  130.     ODNVMethod    void        SetCustomIcon(ODBoolean hasCustomIcon);
  131.     ODNVMethod    ODBoolean    HasCustomIcon();
  132.     ODNVMethod    ODBoolean    IsDirectory();
  133.     ODNVMethod    void        SetCustomIconFamily(ODIconFamily icons);
  134.     ODNVMethod    ODIconFamily    GetCustomIconFamily();
  135.     ODNVMethod    ODBoolean    Exists();
  136.     ODNVMethod    ODUShort    GetFInfoFlags();
  137.     ODNVMethod    void        SetFinderFlag(ODUShort flag);
  138.     ODNVMethod    void        UnsetFinderFlag(ODUShort flag);
  139.     
  140.     ODNVMethod    ODBoolean    IsOpenDocDocument( );
  141.     static        ODBoolean    IsOpenDocDocument( OSType type, OSType creator );
  142.     
  143.  
  144.     // Get & set the Desktop DB comment field
  145.     ODNVMethod    ODIText*    GetComments(ODIText* comments = kODNULL);
  146.     ODNVMethod    void        SetComments(ODIText* comments);
  147.  
  148.     ODNVMethod    void        FlushVolume();
  149.  
  150.     ODNVMethod    ODName*        GetName();
  151.     ODNVMethod    void        GetAsciiName(char* name,ODULong maxLength);
  152.     inline        ODULong        GetAsciiNameLength();
  153.     ODNVMethod    ODOSType    GetPlatformCreator();                    // Macintosh specific
  154.     ODNVMethod    void        SetPlatformCreator(ODOSType fileType);    // Macintosh specific
  155.     ODNVMethod    ODOSType    GetPlatformType();                    // Macintosh specific
  156.     ODNVMethod    void        SetPlatformType(ODOSType fileType);    // Macintosh specific
  157.     ODNVMethod    ODContainerType        GetContainerType();
  158.     ODNVMethod    void        SetContainerType(ODContainerType containerType);
  159.     ODNVMethod    ODPtr        ReadResourcePtr(ODPlatformType resType, ODSShort resID, ODULong* size); // Mac
  160.     ODNVMethod    void        WriteResourcePtr(ODPlatformType resType, ODSShort resID, 
  161.                                             const void *resPtr, ODULong size); // Mac
  162.     ODNVMethod    void        DeleteResource(ODPlatformType resType, ODSShort resID); // Mac
  163.     inline        ODFileSpec&    GetFileSpec();
  164.     ODNVMethod    void        MoveRename( ODFileSpec* newSpec, ODBoolean isDuplicate ) ;
  165.     ODNVMethod    void        Move( ODSLong targetParID ) ;
  166.     ODNVMethod    void        UniquifyName( ODSShort uniquifyingStringID,
  167.                                             StringHandle uniquifyingString,
  168.                                             ODSShort uniquifyingNumberID,
  169.                                             StringHandle uniquifyingNumberString,
  170.                                             short copyCount,
  171.                                             PFUniquifyAction action,
  172.                                             ODBoolean forceNewName);
  173.     ODNVMethod    void        MoveToTrash() ;
  174.     ODNVMethod    void        Rename( Str63 name ) ;
  175.     ODNVMethod    ODTime        GetFileModDate();
  176.     ODNVMethod    void        SetFileModDate(ODTime date);
  177.     ODNVMethod    ODTime        GetFileCreationDate();
  178.     ODNVMethod    void        SetFileCreationDate(ODTime date);
  179.     ODNVMethod    ODULong     GetAllocationBlockSize();
  180.     ODNVMethod    void        BumpFolderModDate();
  181.     
  182.     ODNVMethod    ODBoolean    IsInTrash( );
  183.  
  184. // Methods you must call while the file is open    
  185.     ODNVMethod    void        Close();
  186.  
  187.     ODNVMethod    void        SetFilePos(ODSShort posMode, ODSLong posOff);
  188.     ODNVMethod    ODSLong        GetFilePos();
  189.  
  190.     ODNVMethod    void        Read(void* buffer, ODSLong* count);
  191.     ODNVMethod    void        Write(const void* buffer, ODSLong* count);
  192.  
  193.     ODNVMethod    ODSLong        GetEndOfFile();
  194.     ODNVMethod    void        SetEndOfFile(ODSLong length);
  195.  
  196.     inline        ODFileRefNum    GetFileRefNum();
  197.  
  198.     ODNVMethod    void        CopyFrom( PlatformFile* src );
  199.         
  200.  
  201. private:
  202.     /* Constants to specify the file fork GetLocalPaths should match */
  203.     enum
  204.     {
  205.         kODDataFork        = 0,
  206.         kODResourceFork    = 1
  207.     };
  208.     typedef short ODForkType;
  209.     
  210.     ODNVMethod    void        GetFileID( );
  211.     ODNVMethod    void        UpdateSpecFromID( );
  212.     ODNVMethod    ODBoolean    ActivateResourceFile( ODBoolean &needToCloseResFile );
  213.     
  214.     ODNVMethod    ODFileRefNum GetFirstLocalPath( ODForkType fork );
  215.  
  216.  
  217. public:
  218.     ODNVMethod    ODError        GetLocalPaths(
  219.                               ODForkType fork,
  220.                               ODULong *refNumCount,
  221.                               ODFileRefNumPtr *refNums);
  222.  
  223. /*    Determine if local access paths to a file fork are open.
  224.     The GetLocalPaths function looks through the FCB list to see if
  225.     the fork of the file specified by spec and fork is open by the 
  226.     local File Manager (you should use PBGetCatInfo and check
  227.     ioFlAttrib if you need to see if *anyone* has the file fork open
  228.     *anywhere*). If the result is noErr, GetLocalPaths returns a
  229.     count and a pointer to an array of file refNums (if count is
  230.     not zero) of local access paths to the specified file fork.
  231.  
  232.     spec        input:    An FSSpec record specifying the file.
  233.     fork        input:    Specifies the file fork - either kDataFork
  234.                         or kResourceFork.
  235.     refNumCount    output:    The number of local access paths found.
  236.     refNums        output: If not NULL, a pointer to an array of
  237.                         file refNums - the number of which is
  238.                         specified by refNumCount.  The caller is
  239.                         responsible for disposing of this pointer.
  240. */
  241.  
  242. private:
  243.  
  244.     ODFileSpec            fFileSpec;
  245.     ODSShort            fDataRefNum;
  246.     ODFilePermission    fPermission;
  247.     ODContainerType        fContainerType;
  248.     ODOSType            fCreator;
  249.     ODOSType            fFileType;
  250.     ODScriptCode        fScriptTag;
  251.     ODULong                fFileID;
  252.     ODULong                fVolModDate;
  253.     ODULong                fTimeLastChecked;
  254.     ODFileRefNum        fResRefNum;
  255.     ODULong                fResOpenStack;
  256.     ODBoolean            fNeedToClose;
  257.     
  258.     friend class CWithActiveResources;
  259. };
  260.  
  261.  
  262. //------------------------------------------------------------------------------
  263. // Inline method bodies
  264. //------------------------------------------------------------------------------
  265.  
  266.  
  267. inline ODULong PlatformFile::GetAsciiNameLength()
  268. {
  269.     return fFileSpec.name[0];
  270. }
  271.  
  272. void PlatformFile::SetPermission(ODFilePermission permission)
  273. {
  274.     fPermission = permission;
  275. }
  276.  
  277. inline ODFileSpec& PlatformFile::GetFileSpec()
  278. {
  279.     return fFileSpec;
  280. }
  281.  
  282. inline ODFileRefNum PlatformFile::GetFileRefNum()
  283. {
  284.     return fDataRefNum;
  285. }
  286.  
  287. inline void PlatformFile::SetFileRefNum( ODFileRefNum refNum )
  288. {
  289.     fDataRefNum = refNum;
  290. }
  291.  
  292.  
  293. #ifdef PRAGMA_INTERNAL_SUPPORTED
  294. #pragma internal reset
  295. #endif
  296.  
  297. #endif // _PLFMFILE_
  298.